﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DTO;

namespace BLL
{
    class Selections
    { 
        public int touranmentSelection(Random ran, List<PathTour> pop, int popSize, int touramentSize)
        {
            int[] touranmetGroup = new int[touramentSize];
            int index = 0;
            int tempTour = 0;
            for (int i = 0; i < touramentSize; i++)
            {
                touranmetGroup[i] = ran.Next(popSize);
            }
            for (int i = 0; i < touramentSize - 1; i++)
            {
                index = i;
                for (int j = i + 1; j < touramentSize; j++)
                {
                    if ((pop[touranmetGroup[j]]).Fitness < (pop[touranmetGroup[index]]).Fitness)
                    {
                        index = j;
                    }
                }
                if (index != i)
                {
                    tempTour = touranmetGroup[i];
                    touranmetGroup[i] = touranmetGroup[index];
                    touranmetGroup[index] = tempTour;
                }
            }
            return touranmetGroup[0];
        }

    }
}
